home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c++
- Subject: Re: new and delete with arrays
- Date: 17 Feb 1996 17:38:27 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4g53qj$42i@sparcserver.lrz-muenchen.de>
- References: <4g4loa$i1l@mordred.gatech.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Darin Heuermann <gt1792a@prism.gatech.edu> writes:
-
- >When I allocate an array of classes with delete, should delete call all of
- >the instances' destructors? Here is an example of what I mean.
-
- >//**********************************************
-
- >class MYCLASS {
- >public:
- > MYCLASS(void);
- > ~MYCLASS(void);
- >} // MYCLASS
-
- >MYCLASS *myClass;
-
- >myClass = new MYCLASS[10];
- >delete myClass;
-
- >//**********************************************
-
- >I would expect all 10 instances to call ~MYCLASS() when delete myClass is
- >called, but only the first instance's destructor is being called. Is the
- >a bug in the compiler or is this how it's supposed to work?
-
- Neither the one nor the other, it's a bug in that piece of code. Try
-
- myClass = new MYCLASS[10];
-
- // Work with myClass, then ...
-
- delete [] myClass;
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-
-